package controllers

import (
	"gitee.com/tsingeye/FreeEhome/models"
)

/**
 * @apiDefine record 录像接口
 */
type RecordController struct {
	AuthController
}

/**
 * @api {get} /api/v1/channels/:channelID/queryRecordedFiles 查询指定通道下的录像文件
 * @apiVersion 1.0.0
 * @apiGroup record
 * @apiName QueryRecordedFiles
 * @apiParam {Number} [fileType] 录像类型，默认255--->查询全部
 * @apiParam {String} startTime 开始时间
 * @apiParam {String} stopTime 结束时间
 * @apiSuccessExample  {json} Response-Example
 * {
 *   "errCode": 200,
 *   "errMsg": "OK",
 *   "recordedFiles": [
 *     {
 *       "filename": "ch0001_00000000335000100", //录像文件名
 *       "fileSize": 3668116, //文件大小，字节数
 *       "startTime": "2021-02-02 09:37:54", //开始时间
 *       "stopTime": "2021-02-02 09:47:59" //结束时间
 *     }
 *    ]
 * }
 */
func (this *RecordController) QueryRecordedFiles() {
	//通道ID
	channelID := this.Ctx.Input.Param(":channelID")
	//录像类型
	fileType, err := this.GetInt64("fileType")
	if err != nil {
		//录像类型，默认是按全部进行查询
		fileType = 255
	}
	//开始时间
	startTime := this.GetString("startTime")
	//结束时间
	stopTime := this.GetString("stopTime")

	this.Data["json"] = models.QueryRecordedFiles(channelID, fileType, startTime, stopTime)
	this.ServeJSON()
}

/**
 * @api {get} /api/v1/channels/:channelID/uploadFile 指定通道下的录像文件播放
 * @apiVersion 1.0.0
 * @apiGroup record
 * @apiName UploadFile
 * @apiParam {String} filename 录像文件名
 * @apiSuccessExample  {json} Response-Example
 * {
 *   "errCode": 200,
 *   "errMsg": "OK",
 *   "urlMap": {
 *     "rtmp": "rtmp://127.0.0.1:1935/live/xxx",
 *     "flv": "http://127.0.0.1:80/live/xxx.flv",
 *     "rtsp": "rtsp://127.0.0.1:554/live/xxx",
 *     "hls": "http://127.0.0.1:80/live/xxx/hls.m3u8"
 *    }
 * }
 */
func (this *RecordController) UploadFile() {
	//通道ID
	channelID := this.Ctx.Input.Param(":channelID")
	//录像文件名
	filename := this.GetString("filename")

	this.Data["json"] = models.UploadFile(channelID, filename)
	this.ServeJSON()
}
